<?php
namespace Admin\Controller;

use Util\AccessController;

class PicsController extends AccessController {
    /*
  * 上传多图片
  */
    public function Pics() {
        $upload = new \Think\Upload(); // 实例化上传类
        $upload->maxSize = 5 * 1024 * 1024;// 设置附件上传大小 (-1) 是不限值大小
        $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath = './Upic/';
        $upload->savePath = 'pic/';// 设置附件上传目
        $upload->replace = true; //存在同名文件是否是覆盖
        $upload->subName = array('date', 'Ym');
        $info = $upload->upload();
        $arr = json_decode($_POST['avatar_data'], true);
        $w = $arr['width'];
        $h = $arr['height'];
        $x = $arr['x'];
        $y = $arr['y'];
        if ($info) {
            $PHAT = '.' . ltrim($upload->rootPath, ".") . $info['avatar_file']['savepath'] . $info['avatar_file']['savename'];
            $NEWPATH = '.' . ltrim($upload->rootPath, ".") . $info['avatar_file']['savepath'] . 'CK_' . $info['avatar_file']['savename'];
            $NEWPATH2 = '.' . ltrim($upload->rootPath, ".") . $info['avatar_file']['savepath'] . 'TH_' . $info['avatar_file']['savename'];
            $img = new \Admin\Util\PicUtil;
            $img->crop($PHAT, $w, $h, $x, $y, $NEWPATH);
            $img->thumb($NEWPATH, $w / 3, $h / 3, $NEWPATH2);
            if ($_POST['FIGURE'] == 1) {
                $vo['state'] = 1;
                $vo['picpath'] = $NEWPATH;
                $vo['data'] = $NEWPATH2;
                $this->ajaxReturn($vo);
            } else {
                $vo['state'] = 0;
                $this->ajaxReturn($vo);
            }
        } else {
            $vo['state'] = 0;
            $this->ajaxReturn($vo);
        }
    }
}